﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace KeywordAuction
{
    public class StrategyRaiseAll : StrategyBase
    {
        public override bool Action(Advertiser advertiser)
        {
            foreach (var item in advertiser.Biddings)
            {
                int index = item.AttendingAdspot.GetIndexAdvertiser(item);
                if (index != 0)
                {
                    var value = item.AttendingAdspot.Bitting.OrderByDescending(p => p.Bid).ToList()[index - 1].Bid;
                    item.Bid = value + 1;
                    
                }
                else
                {
                    return false;
                }
            }
            base.Action(advertiser);
            return true;
        }
    }
    public class StrategyDropAll : StrategyBase
   {
       public override bool Action(Advertiser advertiser)
       {
           foreach (var item in advertiser.Biddings)
           {
               var index = item.AttendingAdspot.GetIndexAdvertiser(item);
               if (index != item.AttendingAdspot.Bitting.Count - 1)
               {
                   var value = item.AttendingAdspot.Bitting.OrderByDescending(p => p.Bid).ToList()[index + 1].Bid;
                   if (item.Bid > 0)
                   {
                       item.Bid = value - 1;
                   }
                   else
                   {
                       return false;
                   }

               }
               else
               {
                   return false;
               }
           }

           return base.Action(advertiser);
       }
   }
   public class StrategyHoldAll : StrategyBase
   {
       public override bool Action(Advertiser advertiser)
       {
           return base.Action(advertiser);
       }
   }


    //Hard
   //public class StrategyRaiseDrop : Simulation.Strategy.ValueStrategyBase
   //{
   //    public override bool Action(Advertiser advertiser)
   //    {
   //        advertiser.Biddings.FirstOrDefault().Bid += Value;
   //        if (advertiser.Biddings.LastOrDefault().Bid - Value >= 0)
   //        {
   //            advertiser.Biddings.LastOrDefault().Bid -= Value;
   //        }
   //        else
   //        {
   //            return false;
   //        }
   //       return base.Action(advertiser);
   //    }
   //}

   //public class StrategyRaiseHold : Simulation.Strategy.ValueStrategyBase
   //{
   //    public override bool Action(Advertiser advertiser)
   //    {
   //        advertiser.Biddings.FirstOrDefault().Bid += Value;
   //        base.Action(advertiser);
   //        return true;
   //    }
   //}
   //public class StrategyHoldRaise : Simulation.Strategy.ValueStrategyBase
   //{
   //    public override bool Action(Advertiser advertiser)
   //    {
   //        advertiser.Biddings.LastOrDefault().Bid += Value;
   //        base.Action(advertiser);
   //        return true;
   //    }
   //}
   //public class StrategyDropRaise : Simulation.Strategy.ValueStrategyBase
   //{
   //    public override bool Action(Advertiser advertiser)
   //    {
   //        base.Action(advertiser);
   //        if (advertiser.Biddings.FirstOrDefault().Bid - Value >= 0)
   //        {
   //            advertiser.Biddings.FirstOrDefault().Bid -= Value;
   //        }
   //        else
   //        {
   //            return false;
   //        }
   //        advertiser.Biddings.LastOrDefault().Bid += Value;
   //        return true;
   //    }
   //}

   //public class StrategyDropHold : Simulation.Strategy.ValueStrategyBase
   //{
   //    public override bool Action(Advertiser advertiser)
   //    {
   //        base.Action(advertiser);
   //        if (advertiser.Biddings.FirstOrDefault().Bid - Value >= 0)
   //        {
   //            advertiser.Biddings.FirstOrDefault().Bid -= Value;
   //        }
   //        else
   //        {
   //            return false;
   //        }
   //        return true;
   //    }
   //}

   //public class StrategyHoldDrop : Simulation.Strategy.ValueStrategyBase
   //{
   //    public override bool Action(Advertiser advertiser)
   //    {
   //        base.Action(advertiser);
   //        if (advertiser.Biddings.LastOrDefault().Bid - DropValue >= 0)
   //        {
   //            advertiser.Biddings.LastOrDefault().Bid -= DropValue;
   //        }
   //        else
   //        {
   //            return false;
   //        }
   //        return true;
   //    }
   //}
}
